package com.asiainfo.framework.web.config;

import com.asiainfo.framework.web.resolver.PaginationMethodArgumentResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        boolean hasPaginationMethodArgumentResolver = argumentResolvers.stream()
                .anyMatch(r -> r instanceof PaginationMethodArgumentResolver);
        if (!hasPaginationMethodArgumentResolver) {
            argumentResolvers.add(new PaginationMethodArgumentResolver());
        }
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //文件上传路径
        // registry.addResourceHandler("/resources/**").addResourceLocations("file:" + projectConfig.getProfile());

        //swagger配置
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
